from django.urls import path
from django.urls.converters import register_converter


from .views import index, create_book, shop, register, json_test, login, set_cookie, get_cookie, set_session,\
    get_session, LoginView

# 1. 定义转换器
class MobileConverter:
    regex = '1[3-9]\d{9}'

    # 验证后没有问题的数据，再给试图函数.
    def to_python(self, value):
        return int(value)

    # 进行反解析使用.
    def to_url(self, value):
        return str(value)

# 2. 注册转换器.
register_converter(MobileConverter, 'phone')

urlpatterns = [
    path('', index),
    path('create/', create_book),
    path('shop/<int:city_id>/<int:shop_id>/', shop),
    path('register/', register),
    path('json/', json_test),
    path('login/<phone:mobile>/', login),
    path('set_cookie/', set_cookie),
    path('get_cookie/', get_cookie),
    path('set_session/', set_session),
    path('get_session/', get_session),
    path('login/', LoginView.as_view())
]
